package com.vue.vuedemo.Controller;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.vue.vuedemo.pojo.Sportscircle;
import com.vue.vuedemo.pojo.Team;
import com.vue.vuedemo.pojo.Weijinci;
import com.vue.vuedemo.service.SportsCircleService;
import com.vue.vuedemo.service.TeamService;
import com.vue.vuedemo.service.WeiJinCiService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
@JsonIgnoreProperties({"hibernateLazyInitializer","handler"})
@CrossOrigin(origins = {"http://localhost:8080"}) //当前网站向另一个网站请求数据就是跨域
@Controller
public class WeiJinCiController {


    @Resource
    private WeiJinCiService weiJinCiService;

    @Resource
    private SportsCircleService sportsCircleService;

    //展示违禁词
    @GetMapping(value="weijinciFindAll")
    public List<Weijinci> weijinciFindAll(){
        List<Weijinci> weijinciList = weiJinCiService.weijinciFindAll();
        return weijinciList;
    }


    //添加违禁词
    @PostMapping(value = "weijinciAdd")
    @ResponseBody
    public Integer add(@RequestBody Weijinci weijinci){
        try {
            weiJinCiService.weijinciAdd(weijinci);
            num = 1; //成功
        }catch (Exception ex){
            num = 2; //失败
        }
        return num;
    }

    public Integer num;
    //删除违禁词
    @GetMapping(value = "weijinciDel")
    public Integer teamDel(Integer id){
        try {
            weiJinCiService.weijinciDel(id);
            num = 1; //成功
        }catch (Exception ex){
            num = 2; //失败
        }
        return num;
    }
    //展示违禁帖
    @GetMapping(value="weijinciTieFindAll")
    public List<Sportscircle> weijintie(Sportscircle sportscircle){
        List<Sportscircle> sportscircleList = new ArrayList<Sportscircle>();
        List<Weijinci> weijinciList = weiJinCiService.weijinciFindAll();
        for (Weijinci weijinci:weijinciList) {
            sportscircle = sportsCircleService.sportscircleContext(weijinci.getWname());
            if(sportscircle!=null ){
                sportscircleList.add(sportscircle);
            }
        }
        return sportscircleList;
    }
}
